package com.pureut.production.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.core.utils.bean.BeanUtils;
import com.pureut.production.domain.SysShopModeling;
import com.pureut.production.domain.dto.ModelingMqDto;
import com.pureut.production.mapper.SysShopModelingMapper;
import com.pureut.production.service.SysShopModelingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

/***
 *
 * Author:C
 * Date:2023/03/02 15:13
 * @DESC
 */
@Service
public class SysShopModelingServiceImpl extends ServiceImpl<SysShopModelingMapper, SysShopModeling> implements SysShopModelingService {

    @Resource
    SysShopModelingMapper sysShopModelingMapper;


    @Override
    public void insertSysShopModeling(ModelingMqDto modelingMqDto) {
        if (modelingMqDto.getModelingCode() != null) {
            SysShopModeling sysShopModeling1 = sysShopModelingMapper.selectOne(new QueryWrapper<SysShopModeling>().lambda().eq(SysShopModeling::getModelingCode, modelingMqDto.getModelingCode()));
            if (sysShopModeling1 == null) {
                SysShopModeling sysShopModeling = new SysShopModeling();
                BeanUtils.copyProperties(modelingMqDto, sysShopModeling);
                boolean save = save(sysShopModeling);
                System.out.println(save);
            }
        }
    }

    @Override
    public void updateSysShopModeling(ModelingMqDto modelingMqDto) {

        SysShopModeling sysShopModeling = sysShopModelingMapper.selectOne(new QueryWrapper<SysShopModeling>().lambda().eq(SysShopModeling::getModelingCode, modelingMqDto.getModelingCode()));
        if (sysShopModeling.getModelingCode() != null) {
            BeanUtils.copyProperties(modelingMqDto, sysShopModeling);
            int i = sysShopModelingMapper.updateById(sysShopModeling);
            System.out.println(i);
        }


    }

    /**
     * 删除
     *
     * @param modelingMqDto
     */
    @Override
    public void deleteSysShopModeling(ModelingMqDto modelingMqDto) {
        if (modelingMqDto.getModelingCode() != null) {
            List<String> codes = Arrays.asList(modelingMqDto.getModelingCode().split(","));
            List<SysShopModeling> sysShopModelings = sysShopModelingMapper.selectList(new QueryWrapper<SysShopModeling>().lambda().in(SysShopModeling::getModelingCode, codes));
            if (sysShopModelings.size() > 0) {
                removeBatchByIds(sysShopModelings);
            }
        }
    }
}
